<?php 
    include ("config.inc.php");
    
    // capture data from form and store in variables
	$minutes      = toMinutes(escape('minutes'));
    $completed    = escape('completed');
    $a_id         = escape('who');
    $p_id         = escape('p_id');
	$u_id         = escape('u_id');
	$workdate     = escape('workdate');
	
	if(!$workdate) $workdate = 'curdate()';
	else $workdate = "'".date('Y-m-d',strtotime($workdate))."'"; # tranform and quote date value
	if($completed == 1){
		$completed_query = "UPDATE updates SET date_completed=$workdate WHERE u_id=$u_id";
		mysql_query($completed_query) or die(mysql_error());
	}
	
	$work = "INSERT INTO work (p_id,a_id,workdate,minutes) VALUES ($p_id,$a_id,$workdate,$minutes)";
	echo $work;
	mysql_query($work) or die(mysql_error());
	
	$values = array (
			"minutes" => $minutes,
			"who" => $a_id,
			"completed" => $completed
			//etc
	);
	echo json_encode($values);
?>